package org.adream.account.rest.api;

import javax.servlet.http.HttpServletRequest;

import org.adream.account.entity.UserDetailEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.service.BankInfoService;
import org.adream.account.util.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.util.StringUtils;

@RequestMapping("/bankInfo")
@Controller
public class BankInfoApiController {
	
	private final static Logger logger = LoggerFactory.getLogger(BankInfoApiController.class);
	
	@Autowired
	private BankInfoService bankInfoService;
	
	/**
	 * 查询用户银行信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public ResultModel<UserDetailEntity> queryBankInfo(HttpServletRequest request){
		String uid = UserUtil.getUidByRequest(request);
		if(StringUtils.isEmpty(uid)) {
			logger.warn("查询银行信息失败,登录信息失效");
			return new ResultModel<UserDetailEntity>(ResultModel.NOT_FOUND_OBJECT, "登录信息失效,请重新登录", null);
		}
		UserDetailEntity userDetail = bankInfoService.queryBasicInfo(uid);
		if(userDetail == null) {
			logger.warn("查询银行信息失败,用户详细信息不存在uid:{}", uid);
			return new ResultModel<UserDetailEntity>(ResultModel.NOT_FOUND_OBJECT, "查询失败,用户信息不存在", null);
		}
		return new ResultModel<UserDetailEntity>(ResultModel.SUCCESS, "查询成功", userDetail);
	}
}